window.onload = function () {
    // 默认选中
    $('.message').addClass('weui-bar__item--on')
    $('#tab1').addClass('weui-tab__bd-item--active')
    // 切换
    $('.message').click(function () {
        $('.message').addClass('weui-bar__item--on')
        $('.history').removeClass('weui-bar__item--on')
        $('#tab1').addClass('weui-tab__bd-item--active')
        $('#tab2').removeClass('weui-tab__bd-item--active')
    })
    $('.history').click(function () {
        $('.message').removeClass('weui-bar__item--on')
        $('.history').addClass('weui-bar__item--on')
        $('#tab1').removeClass('weui-tab__bd-item--active')
        $('#tab2').addClass('weui-tab__bd-item--active')
    })
    // 不通过  待定  通过
    $('.Btn').click(function () {
        let id = $(this).attr("id");
        var status;
        var value;
        if (id === 'BtnNoPass') {
            status = 1
            value = $("#" + id).html()
        }
        if (id === 'BtnIndex') {
            status = 2
            value = $("#" + id).html()
        }
        if (id === 'BtnPass') {
            status = 3
            value = $("#" + id).html()
        }
        $.modal({
            title: "温馨提示",
            text: "该应聘者为" + value,
            buttons: [
                {
                    text: "确定",
                    onClick: function () {
                        let key = '195a9b99ea7a0d259151b5c412bb631b';
                        $.ajax({
                            type: "post",
                            url: "http://hplqytest.suoluomei.cn/index.php?s=/Hr/Index/throughResultsSave",
                            data: {
                                api_key: key,
                                status: status
                            },
                            success: function (result) {
                                // console.log(result)
                                $('.Btn').unbind("click")
                            },
                            error: function () {

                            }
                        })
                    }
                },
                {
                    text: "取消",
                    className: "default",
                    onClick: function () {

                    }
                },
            ]
        });
    })
    // 判断输入文字最少10个字符
    // var counter;
    // $("#detail2_num").text(counter2);
    // $("#detail2").on('blur keyup input', function () {
    //     var text = $("#detail2").val();
    //     counter = text.length;
    //     // console.log(counter)
    //     $("#detail2_num").text(counter);
    // });
    // 评价提交
    $('.popupBtn').click(function () {
        let value = $('textarea[name=msg]').val()
        let counter = value.length;
        if (value == '') {
            $.toast("评价不能为空！", "forbidden");
            return false
        }
        if (counter <= 10) {
            $.toast("不低于10字符！", "forbidden");
            return false
        }
        let key = '195a9b99ea7a0d259151b5c412bb631b';
        $.ajax({
            type: "post",
            url: "http://hplqytest.suoluomei.cn/index.php?s=/Hr/Index/phraseSave",
            data: {
                api_key: key,
                value: value
            },
            success: function (result) {
                // console.log(result)
                $('textarea[name=msg]').val('')
                $('.weui_popupBg').fadeOut(600)
                setTimeout(function () {
                    $.toast("保存成功！");
                }, 600)
                $('.popupBtn').unbind("click")
                $('.mainSuspend').unbind("click")
            },
            error: function () {

            }
        })
    })
    // 所有input禁用
    $("input[type='text']").attr("disabled", "disabled");
    $("input[type='number']").attr("disabled", "disabled");
    $("input[type='radio']").attr("disabled", "disabled");
    // 获取当前应聘者信息
    $.ajax({
        type: "POST",
        url: 'http://hplqytest.suoluomei.cn/index.php?s=/Hr/Index/getEvaluateSave',
        data: {
            api_key: '195a9b99ea7a0d259151b5c412bb631b',
            userid: ''
        },
        dataType: "json",
        success: function (data) {
            // console.log(data)
            $('.mainName').html(data.data.result.name)
            $('.mainZw').html('应聘职位：' + data.data.result.job_name)
            $('.mainJd').html('所在阶段：' + data.data.result.status_name)
            $('#my-input').val(data.data.result.updatetime)
            $('#typeTrench').val(data.data.result.channel_type_name)
            $('#trench').val(data.data.result.channel_name)
            var sex = data.data.result.sex
            if (sex == '男') {
                $($("input[name='radio1']")[1]).attr('checked', '1')
            } else {
                $($("input[name='radio1']")[0]).attr('checked', '0')
            }
            $('#phone').val(data.data.result.mobile)
            $('.dz').val(data.data.result.address)
            $('.ssz').val(data.data.result.idcard)
            $('.hy').val(data.data.result.marriage)
            $('#email').val(data.data.result.email)
            $('#native').val(data.data.result.native_place)
            $('#nation').val(data.data.result.nation)
            $('#my-input1').val(data.data.result.birth)
            if (data.data.study.length > 0) {
                for (let i = 0; i < data.data.study.length; i++) {
                    let myli = "<div class=\"experListTop deteleBox\">\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">开始时间</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input my-input\" name=\"jytime\" id=\"kaishi\" type=\"text\"\n" +
                        "                                                       value=" + data.data.study[i].start_date + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">结束时间</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input my-input\" name=\"jytime\" id=\"end\" type=\"text\"\n" +
                        "                                                       value=" + data.data.study[i].end_date + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">毕业院校全称</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input\" name=\"jytime\" type=\"text\"\n" +
                        "                                                       placeholder=\"请填写毕业院校\" value=" + data.data.study[i].school_name + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">专业</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input\" name=\"jytime\" type=\"text\" placeholder=\"请填写专业\" value=" + data.data.study[i].major + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">学历及学位</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input educa\" name=\"jytime\" id=\"educa\" type=\"text\"\n" +
                        "                                                       placeholder=\"-- 请选择 --\" value=" + data.data.study[i].degree_name + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                    </div>";
                    $('.studyList').append(myli);
                }
            } else {
                let myli = "<div class=\"experListTop deteleBox\">\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">开始时间</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input my-input\" name=\"jytime\" id=\"kaishi\" type=\"text\"\n" +
                    "                                                       value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">结束时间</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input my-input\" name=\"jytime\" id=\"end\" type=\"text\"\n" +
                    "                                                       value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">毕业院校全称</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input\" name=\"jytime\" type=\"text\"\n" +
                    "                                                       placeholder=\"请填写毕业院校\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">专业</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input\" name=\"jytime\" type=\"text\" placeholder=\"请填写专业\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">学历及学位</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input educa\" name=\"jytime\" id=\"educa\" type=\"text\"\n" +
                    "                                                       placeholder=\"-- 请选择 --\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                    </div>";
                $('.studyList').append(myli);
            }
            if (data.data.work.length > 0) {
                for (let i = 0; i < data.data.work.length; i++) {
                    let myli = "<div class=\"experListTop deteleBox1\">\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">开始时间</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input my-input\" name=\"jltime\" id=\"my-input3\"\n" +
                        "                                                       type=\"text\" value=" + data.data.work[i].start_date + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">结束时间</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input my-input\" name=\"jltime\" id=\"my-input4\"\n" +
                        "                                                       type=\"text\" value=" + data.data.work[i].end_date + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">工作单位全称</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                        "                                                       placeholder=\"请填写工作单位\" value=" + data.data.work[i].company_name + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">部门及职位</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                        "                                                       placeholder=\"请填写部门及职位\" value=" + data.data.work[i].job_name + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">离职原因</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                        "                                                       placeholder=\"请填写离职原因\" value=" + data.data.work[i].leave_reason + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">证明人</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                        "                                                       placeholder=\"请填写姓名\" value=" + data.data.work[i].prove_username + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                        <div class=\"weui_cell\">\n" +
                        "                                            <div class=\"weui_cell_hd\">\n" +
                        "                                                <label class=\"weui_label\">电话</label>\n" +
                        "                                            </div>\n" +
                        "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                        "                                                <input class=\"weui_input outfocus verify\" id=\"zmrPhone\" name=\"jltime\"\n" +
                        "                                                       type=\"number\" placeholder=\"请填写电话号码\" value=" + data.data.work[i].prove_mobile + ">\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                    </div>";
                    $('.workList').append(myli);
                }
            } else {
                let myli = "<div class=\"experListTop deteleBox1\">\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">开始时间</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input my-input\" name=\"jltime\" id=\"my-input3\"\n" +
                    "                                                       type=\"text\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\"><label for=\"\" class=\"weui_label\">结束时间</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input my-input\" name=\"jltime\" id=\"my-input4\"\n" +
                    "                                                       type=\"text\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">工作单位全称</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                    "                                                       placeholder=\"请填写工作单位\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">部门及职位</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                    "                                                       placeholder=\"请填写部门及职位\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">离职原因</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                    "                                                       placeholder=\"请填写离职原因\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">证明人</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input outfocus\" name=\"jltime\" type=\"text\"\n" +
                    "                                                       placeholder=\"请填写姓名\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                        <div class=\"weui_cell\">\n" +
                    "                                            <div class=\"weui_cell_hd\">\n" +
                    "                                                <label class=\"weui_label\">电话</label>\n" +
                    "                                            </div>\n" +
                    "                                            <div class=\"weui_cell_bd weui_cell_primary\">\n" +
                    "                                                <input class=\"weui_input outfocus verify\" id=\"zmrPhone\" name=\"jltime\"\n" +
                    "                                                       type=\"number\" placeholder=\"请填写电话号码\" value=\"\">\n" +
                    "                                            </div>\n" +
                    "                                        </div>\n" +
                    "                                    </div>";
                $('.workList').append(myli);
            }
        },
        error: function () {

        }
    })
    // 获取当前应聘者历史记录
    $.ajax({
        type: "POST",
        url: 'http://hplqytest.suoluomei.cn/index.php?s=/Hr/Index/getInterviewResultsSave',
        data: {
            api_key: '195a9b99ea7a0d259151b5c412bb631b',
            userid: ''
        },
        dataType: "json",
        success: function (data) {
            // console.log(data)
            if (data.data.result.length > 0) {
                for (let i = 0; i < data.data.result.length; i++) {
                    let myli = "<li class=\"node-icon\">\n" +
                        "                                        <i class=\"node-icon\"></i>\n" +
                        "                                        <div class=\"history\">\n" +
                        "                                            <p>面试时间：" + data.data.result[i].updatetime + "</p>\n" +
                        "                                            <div class=\"line\"></div>\n" +
                        "                                            <div class=\"history-event\">\n" +
                        "                                                <p>所在阶段：" + data.data.result[i].step + "</p>\n" +
                        "                                                <p>面试评价：" + data.data.result[i].remark + "</p>\n" +
                        "                                            </div>\n" +
                        "                                        </div>\n" +
                        "                                    </li>";
                    $('.track-Ul').append(myli);
                }
            } else {
                $('.without').css('display', 'block')
                $('.track-rcol').css('display', 'none')
            }
        },
        error: function () {
            $('.without').css('display', 'block')
            $('.track-rcol').css('display', 'none')
        }
    })
    // 点击显示评价
    $(".mainSuspend").click(function () {
        $('.weui_popupBg').fadeIn(600)
        document.body.addEventListener("touchmove", disableScroll, {passive: false});
    });
    // 关闭评价
    $(".popupBg").click(function () {
        $('.weui_popupBg').fadeOut(600)
        document.body.removeEventListener("touchmove", disableScroll, { passive: false });
    });
    // 关闭评价
    $(".popupAddImg").click(function () {
        $('.weui_popupBg').fadeOut(600)
        document.body.removeEventListener("touchmove", disableScroll, { passive: false });
    });
    // 遍历应聘者附件
    $(".wendang1").click(function () {
        location.href = "http://sucai.suoluomei.cn/sucai/file/20181017/585d87ca69c18000e90ff456c1835be1.doc"
    })
    $(".wendang2").click(function () {
        location.href = "http://sucai.suoluomei.cn/sucai/file/20181017/96cfbeb8d669aa3d17d00840e46bd006.pdf"
    })

}
function disableScroll(e){
    e.preventDefault();
}

